package com.cjk.foundation.dao.file;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.cjk.foundation.entity.file.AdEntity;
import com.cjk.foundation.enums.ConfStatus;

@Repository
public interface AdDao {
	
	@Insert("insert into ad(group_id, user_id, status) values(#{groupId}, #{userId}, #{status}) on duplicate key update user_id = values(user_id), status = values(status)")
	public void insert(@Param("groupId") Integer groupId, @Param("userId") Integer userId, @Param("status") ConfStatus status);

	public List<AdEntity> selectListByCondition(@Param("userId") Integer userId, @Param("groupIds") List<Integer> groupIds, @Param("page") Integer page, @Param("pageSize") Integer pageSize);
	
	public Integer selectCountByCondition(@Param("userId") Integer userId, @Param("groupIds") List<Integer> groupIds);
	
	@Delete("delete from ad where group_id = #{groupId}")
	public void deleteById(@Param("groupId") Integer groupId);
	
	@Update("update `ad` set status = #{status}, last_conf_time = #{lastConfTime} where group_id = #{groupId}")
	public void conf(@Param("status") ConfStatus status, @Param("lastConfTime") Date lastConfTime, @Param("groupId") Integer groupId);
	
}
